package io.renren.modules.member_group.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.member_group.entity.V9MemberGroupEntity;
import io.renren.modules.member_group.service.V9MemberGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 管理会员组
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-09-21 15:00:55
 */
@RestController
@RequestMapping("member_group/v9membergroup")
public class V9MemberGroupController {
    @Autowired
    private V9MemberGroupService v9MemberGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("member_group:v9membergroup:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = v9MemberGroupService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{groupid}")
    @RequiresPermissions("member_group:v9membergroup:info")
    public R info(@PathVariable("groupid") Integer groupid){
		V9MemberGroupEntity v9MemberGroup = v9MemberGroupService.getById(groupid);

        return R.ok().put("v9MemberGroup", v9MemberGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("member_group:v9membergroup:save")
    public R save(@RequestBody V9MemberGroupEntity v9MemberGroup){
		v9MemberGroupService.save(v9MemberGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("member_group:v9membergroup:update")
    public R update(@RequestBody V9MemberGroupEntity v9MemberGroup){
		v9MemberGroupService.updateById(v9MemberGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("member_group:v9membergroup:delete")
    public R delete(@RequestBody Integer[] groupids){
		v9MemberGroupService.removeByIds(Arrays.asList(groupids));

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/setorder")
    public R setorder(@RequestParam Map<String, Object> params){
        v9MemberGroupService.updateListorder(params);
        return R.ok();
    }

}
